#include <stdio.h>

/*
 * 内联函数
 */

inline int max(int a, int b)
{
    if (a > b)
        return a;

    return b;
}

int max(int a, int b);

int main(int argc, char **argv)
{
    printf("%x\n", max(0x666, 0x777));
    printf("%x\n", max(0x666, argc));
    printf("%x\n", max(0x666, argc));

    return 0;
}

#if 0

/*
 * intel
 */
0000000000001149 <max>:
    1149:	f3 0f 1e fa          	endbr64 
    114d:	55                   	push   %rbp				// rsp=rsp-8, (rsp)=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
    114e:	48 89 e5             	mov    %rsp,%rbp		// rbp=rsp
    1151:	89 7d fc             	mov    %edi,-0x4(%rbp)	// edi = parameter1, 0x666
    1154:	89 75 f8             	mov    %esi,-0x8(%rbp)	// esi = parameter2, 0x777
    1157:	8b 45 fc             	mov    -0x4(%rbp),%eax	// eax = parameter1
    115a:	3b 45 f8             	cmp    -0x8(%rbp),%eax	// parameter1 - parameter2
    115d:	7e 05                	jle    1164 <max+0x1b>	// CMP指令的第一个操作表达式小于或等于(不大于)第二个表达式，JLE将跳转到指令所标明的地址；
    115f:	8b 45 fc             	mov    -0x4(%rbp),%eax	// eax = return value = parameter1, 0x666
    1162:	eb 03                	jmp    1167 <max+0x1e>	// 跳转到函数结尾
    1164:	8b 45 f8             	mov    -0x8(%rbp),%eax	// eax = return value = parameter2, 0x777
    1167:	5d                   	pop    %rbp				// rbp=(rsp), rsp+8 ===> movq (%rsp),%rbp) addq $8, %rsp
    1168:	c3                   	retq					// ===> pop %rip

0000000000001169 <main>:
    1169:	f3 0f 1e fa          	endbr64 
    116d:	55                   	push   %rbp				// rsp=rsp-8, rsp=rbp ===> subq $8,%rsp, movq %rbp,(%rsp)
    116e:	48 89 e5             	mov    %rsp,%rbp		// rbp=rsp
    1171:	48 83 ec 10          	sub    $0x10,%rsp		// rsp=rsp-0x10
    1175:	89 7d fc             	mov    %edi,-0x4(%rbp)	// rbp-0x4 = edi = argc
    1178:	48 89 75 f0          	mov    %rsi,-0x10(%rbp)	// rbp=0x10 = rsi = argv
    117c:	be 77 07 00 00       	mov    $0x777,%esi		// esi = 0x777
    1181:	bf 66 06 00 00       	mov    $0x666,%edi		// edi = 0x666
    1186:	e8 be ff ff ff       	callq  1149 <max>		// max(edi, esi)
    118b:	89 c6                	mov    %eax,%esi		// esi = return value
    118d:	48 8d 3d 70 0e 00 00 	lea    0xe70(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
    1194:	b8 00 00 00 00       	mov    $0x0,%eax		// eax = 0
    1199:	e8 b2 fe ff ff       	callq  1050 <printf@plt>	// printf(rdi, esi)
    119e:	8b 45 fc             	mov    -0x4(%rbp),%eax	// eax = rbp-0x4 (argc)
    11a1:	89 c6                	mov    %eax,%esi		// esi = eax
    11a3:	bf 66 06 00 00       	mov    $0x666,%edi		// edi = 0x666
    11a8:	e8 9c ff ff ff       	callq  1149 <max>		// max(edi, esi)
    11ad:	89 c6                	mov    %eax,%esi		// esi = return value
    11af:	48 8d 3d 4e 0e 00 00 	lea    0xe4e(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
    11b6:	b8 00 00 00 00       	mov    $0x0,%eax		// eax = 0
    11bb:	e8 90 fe ff ff       	callq  1050 <printf@plt>	// printf(rdi, esi)
    11c0:	8b 45 fc             	mov    -0x4(%rbp),%eax	// eax = rbp-0x4 (argc)
    11c3:	89 c6                	mov    %eax,%esi		// esi = eax
    11c5:	bf 66 06 00 00       	mov    $0x666,%edi		// edi = 0x666
    11ca:	e8 7a ff ff ff       	callq  1149 <max>		// max(edi, esi)
    11cf:	89 c6                	mov    %eax,%esi		// esi = return value
    11d1:	48 8d 3d 2c 0e 00 00 	lea    0xe2c(%rip),%rdi        # 2004 <_IO_stdin_used+0x4> // rdi = "%x\n"
    11d8:	b8 00 00 00 00       	mov    $0x0,%eax		// eax = 0
    11dd:	e8 6e fe ff ff       	callq  1050 <printf@plt>	// printf(rdi, esi)
    11e2:	b8 00 00 00 00       	mov    $0x0,%eax		// return value 0
    11e7:	c9                   	leaveq					// ===> mov %rbp,%rsp, pop %rbp
    11e8:	c3                   	retq					// ===> pop %rip
    11e9:	0f 1f 80 00 00 00 00 	nopl   0x0(%rax)		// 流水线指令优化

/*
 * arm
 */
000000000040055c <max>:
  40055c:	d10043ff 	sub	sp, sp, #0x10			// sp = sp-0x10
  400560:	b9000fe0 	str	w0, [sp, #12]			// sp+12 = w0
  400564:	b9000be1 	str	w1, [sp, #8]			// sp+8 = w1
  400568:	b9400fe1 	ldr	w1, [sp, #12]			// w1 = sp+12
  40056c:	b9400be0 	ldr	w0, [sp, #8]			// w0 = sp+8
  400570:	6b00003f 	cmp	w1, w0					// w1-w0
  400574:	5400006d 	b.le	400580 <max+0x24>	// <=	
  400578:	b9400fe0 	ldr	w0, [sp, #12]			// w0 = sp+12
  40057c:	14000002 	b	400584 <max+0x28>		// 跳转到函数结尾
  400580:	b9400be0 	ldr	w0, [sp, #8]			// w0 = sp+8
  400584:	910043ff 	add	sp, sp, #0x10			// sp = sp+0x10
  400588:	d65f03c0 	ret

000000000040058c <main>:
  40058c:	a9be7bfd 	stp	x29, x30, [sp, #-32]!	// sp=sp-32, sp=x29=fp, sp+8=x30=lr
  400590:	910003fd 	mov	x29, sp					// x29=fp=sp
  400594:	b9001fa0 	str	w0, [x29, #28]			// x29+28=w0=argc
  400598:	f9000ba1 	str	x1, [x29, #16]			// x29+16=x1=argv
  40059c:	5280eee1 	mov	w1, #0x777                 	// #1911
  4005a0:	5280ccc0 	mov	w0, #0x666                 	// #1638
  4005a4:	97ffffee 	bl	40055c <max>			// max(w0, w1)
  4005a8:	2a0003e1 	mov	w1, w0					// w1=w0=return value
  4005ac:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005b0:	911ac000 	add	x0, x0, #0x6b0			// x0="%x\n"
  4005b4:	97ffffa7 	bl	400450 <printf@plt>		// printf(x0, w1)
  4005b8:	b9401fa1 	ldr	w1, [x29, #28]			// w1 = x29+28 = argc
  4005bc:	5280ccc0 	mov	w0, #0x666                 	// #1638
  4005c0:	97ffffe7 	bl	40055c <max>			// max(w0, w1)
  4005c4:	2a0003e1 	mov	w1, w0					// w1 = w0 = return value
  4005c8:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005cc:	911ac000 	add	x0, x0, #0x6b0			// x0="%x\n"
  4005d0:	97ffffa0 	bl	400450 <printf@plt>		// printf(x0, w1)
  4005d4:	b9401fa1 	ldr	w1, [x29, #28]			// w1 = x29+28 = argc
  4005d8:	5280ccc0 	mov	w0, #0x666                 	// #1638
  4005dc:	97ffffe0 	bl	40055c <max>			// max(w0, w1)
  4005e0:	2a0003e1 	mov	w1, w0					// w1 = w0 = return value
  4005e4:	90000000 	adrp	x0, 400000 <_init-0x3e8>
  4005e8:	911ac000 	add	x0, x0, #0x6b0			// x0="%x\n"
  4005ec:	97ffff99 	bl	400450 <printf@plt>		// printf(x0, w1)
  4005f0:	52800000 	mov	w0, #0x0                   	// #0
  4005f4:	a8c27bfd 	ldp	x29, x30, [sp], #32		// fp=x29=sp, lr=x30=sp+8, sp=sp+32
  4005f8:	d65f03c0 	ret
  4005fc:	00000000 	.inst	0x00000000 ; undefined

#endif
